<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 400px;
            border-bottom: 1px solid #ccc;
            margin: 100px auto;
        }

        .box input {
            width: 370px;
            height: 30px;
            border: 0;
            outline: none;
        }

        .box label {
            position: relative;
            width: 400px;
        }

        .box label span {
            position: absolute;
            top: 4px;
            right: 2px;
            width: 10px;
            /* float: right; */
        }
    </style>
</head>

<body>
    <div class="box">

        <input type="password" name="pwd" id="pwd">
        <label for="">
            <span id="kai">?</span>
        </label>
    </div>
    <script>
        //获取元素
        let kai = document.getElementById("kai");
        let pwd = document.getElementById("pwd");
        //处理事件
        let flag = 0;
        kai.onclick = function () {
            if (flag == 0) {
                pwd.type = 'text';
                kai.innerHTML = "!";
                flag = 1;

            } else {
                pwd.type = 'password';
                kai.innerText = "?";
            }

        }

    </script>
</body>

</html>